<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="排序号" prop="sortNo">
						<el-input-number v-model="form.sortNo" placeholder="排序号"></el-input-number>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="招聘计划" prop="planId">
						<sc-select v-model="form.planId" :apiObj="$API.hr.hrRecruitPlan.getHrRecruitPlanForSelect" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="需求标题" prop="title">
				<el-input v-model="form.title" placeholder="需求标题" maxlength="80" clearable></el-input>
			</el-form-item>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="招聘部门" prop="deptName">
						<el-input v-model="form.deptName" placeholder="招聘部门" maxlength="80" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="招聘人数" prop="userCount">
						<el-input-number v-model="form.userCount" placeholder="招聘人数" clearable></el-input-number>/人
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="人员特长" prop="skills">
						<el-input v-model="form.skills" placeholder="人员特长" maxlength="80" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="所学专业" prop="major">
						<el-input v-model="form.major" placeholder="所学专业" maxlength="80" clearable></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="招聘工种" prop="workJob">
						<sc-select v-model="form.workJob" :params="{code:'workJob'}" :apiObj="$API.hr.hrDic.getHrDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="要求学历" prop="education">
						<sc-select v-model="form.education" :params="{code:'education'}" :apiObj="$API.hr.hrDic.getHrDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="要求性别" prop="sex">
						<el-radio-group v-model="form.sex">
							<el-radio-button :label="0">不限</el-radio-button>
							<el-radio-button :label="1">男</el-radio-button>
							<el-radio-button :label="2">女</el-radio-button>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="出生日期" prop="birthDay">
						<el-date-picker v-model="form.birthDay" placeholder="出生日期" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="招聘类型" prop="occupation">
						<sc-select v-model="form.occupation" :params="{code:'occupationType'}" :apiObj="$API.hr.hrDic.getHrDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="到岗日期" prop="lastTime">
						<el-date-picker v-model="form.lastTime" placeholder="到岗日期" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="招聘备注">
				<el-input v-model="form.remark" placeholder="招聘备注" clearable maxlength="380" type="textarea"></el-input>
			</el-form-item>
			<el-form-item label="相关附件" prop="attachId">
				<sc-upload-file :apiObj="apiObj" v-model="fileList" :data="{module:'hr'}" :showFileList="false" @success="addNewFile">
					<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
				</sc-upload-file>
				<attach-menu v-model:attachIds="form.attachId" :roleFlag="4" :preview="true"></attach-menu>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectHrUserDialog from "@/views/module/selectHrUserDialog";
import AttachMenu from '@/views/module/attachMenu'
export default {
	emits: ['success', 'closed'],
	components: {
		selectHrUserDialog,AttachMenu
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			mode: "add",
			btName: "保存",
			titleMap: {
				add: '创建招聘需求',
				edit: '编辑招聘需求',
				show: '查看'
			},
			fileList: [],
			apiObj: this.$API.file.attach.uploadFile,
			templateList: [],
			templates: [],
			form: {
				recordId: '',
				sortNo: '',
				planId:'',
				title: '',
				deptName: '',
				userCount: 0,
				skills: '',
				major: "",
				workJob: '',
				education: '',
				sex: '0',
				birthDay: '',
				occupation: '',
				lastTime: '',
				attachId: '',
				remark: ''
			},
			rules: {
				title: [
					{required: true, message: '需求标题不能为空'}
				],
				userCount: [
					{required: true, message: '招聘人数不能为空'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.hr.hrRecruitNeeds.insertHrRecruitNeeds.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.hr.hrRecruitNeeds.updateHrRecruitNeeds.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.recordId = data.recordId
			this.form.sortNo = data.sortNo
			this.form.planId = data.planId
			this.form.title = data.title
			this.form.deptName = data.deptName
			this.form.major = data.major
			this.form.userCount = data.userCount
			this.form.skills = data.skills
			this.form.workJob = data.workJob
			this.form.education = data.education
			this.form.sex = data.sex
			this.form.birthDay = data.birthDay
			this.form.occupation = data.occupation
			this.form.lastTime = data.lastTime
			this.form.attachId = data.attachId
			this.form.remark = data.remark
		},
		addNewFile(res, file)
		{
			let tArr =[];
			if(this.form.attachId!=undefined&&this.form.attachId!=null&&this.form.attachId!=''){
				tArr = this.form.attachId.split(",");
			}
			tArr.push(res.data.attachId);
			this.form.attachId = tArr.join(",");
		}
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
